const baseUrl = "https://www.2306.tech/CCShop/"

const request = (url = '', data = {}, type = 'GET', header = {}) => {
	return new Promise((resolve, reject) => {
		
		console.log("send request to"+baseUrl+url);
		
		uni.request({
			method: type,
			url: baseUrl + url,
			data: data,
			header: header,
			success: (response) => {
				console.log("response: ",response);
				if(response.statusCode != 200) {
					uni.showToast({
						title:'服务器繁忙，请稍后再试',
						icon:'none'
					})
				}
				resolve(response.data);
			},
			fail: (error) => {
				uni.showToast({
					title:'连接超时，请检查网络',
					icon:'none'
				})
				let [err, res] = error;
				reject(err)
				
			},
			complete: () => {
				uni.hideLoading()
			}
		})
	});
}
export default request;
